package com.white.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.white.bean.Article;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ArticleMapper extends BaseMapper<Article> {
    String HOT_ARTICLE_VIEW = " hotArticleView ";
    String RECOMMEND_ARTICLE_VIEW = " recommendArticleView ";
    String TABLE_NAME = " article ";
    String SELECT = "select * from" + TABLE_NAME + "where ";
    String CREATE_TIME = "createTime";
    int LIMIT = 10;

    @Select("select * from" + RECOMMEND_ARTICLE_VIEW + "where classifyId = #{classifyId} limit " + LIMIT)
    List<Article> getArticleListByClassifyId(Long classifyId);
    /**
     * 针对用户模型返回推荐文章
     * @param recommendUserId 用户ID
     * @return
     */
    @Select("select * from" + RECOMMEND_ARTICLE_VIEW + "where recommendUserId = #{recommendUserId}")
    List<Article> getRecommendArticle(Long recommendUserId);


    @Select("select * from" + RECOMMEND_ARTICLE_VIEW + " where recommendUserId = #{recommendUserId} limit #{page}, #{limit}")
    List<Article> getRecommendArticleByPage(Long recommendUserId, int page, int limit);

    /**
     * 获取热门文章
     * @return
     */

    @Select("select * from" + HOT_ARTICLE_VIEW + "limit " + LIMIT)
    List<Article> getHotArticle();


    @Select("select * from" + HOT_ARTICLE_VIEW + "limit #{page}, #{limit}")
    List<Article> getHotArticleByPage(int page, int limit);


    @Select("select * from" + HOT_ARTICLE_VIEW + " where title like #{content} limit " + LIMIT)
    List<Article> search(String content);

    @Select("select * from" + HOT_ARTICLE_VIEW + " where articleId in (" +
            "select articleId from thumbsUp where userId = #{userId}) limit " + LIMIT)
    List<Article> getLikeArticleByUserId(Long userId);

    @Update("update " + TABLE_NAME + "set views = views + 1 where articleId = #{articleId}")
    void viewsInc(Long articleId);

    @Select(SELECT + "articleId = #{articleId} limit 1")
    Article getByArticleId(Long articleId);
}
